package com.example.stock.business.monitor.logic;

import com.example.stock.excel.Monitor;
import com.example.stock.model.MonthDetail;
import com.example.stock.service.MonthDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 月分位点统计
 */
@Component
public class MonthLpMonitor implements Trigger{

    @Autowired
    MonthDataService monthDataService;

    @Override
    public boolean trigger(Monitor monitor) {
        // 获取给定股票的月份细节数据
        MonthDetail currentMonthDetail = monthDataService.getCurrentMonthDetail(monitor.getStock());
        if (currentMonthDetail == null) {
            return false;
        }

        double m = Double.parseDouble(monitor.getExtra());
        return switch (monitor.getCategory()) {
            case "LP_UP" -> currentMonthDetail.getLp() >= m;
            case "LP_DOWN" -> currentMonthDetail.getLp() < m;
            case "REL_LP_DOWN" -> currentMonthDetail.getRelLP() < m;
            default -> false;
        };
    }
}
